/**
 * Created by admin on 2017/9/21.
 */
/**
 * Created by yhg97p on 2016/9/27.
 */
define(['app', 'filters/filters'],function(app){
    app.register.controller('compLive', function($scope, $http, $state, $sce,$stateParams,$rootScope){
        $scope.loading_show = true;//加载图
        $scope.tip = 0;
        $scope.tipShowzy = false;
        $scope.content_upload = 0;//点击加载默认隐藏
        $http({//请求公开课-列表接口
            url: app._baseUrl + 'Qy/PublicCurr/index',
            method: 'POST',
            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        }).success(function(res){
            if(res.success){//默认加载1页
                $scope.total = res.page.total;
                $scope.loading_show = false;
                $scope.page = res.page;
                if($scope.page.total==0){//没有条数
                    $scope.tip = 1;//空页面
                }else{
                    $scope.tip = 0;//有值页面
                    $scope.Majorinfog=res.data;
                    if($scope.page.page_total>1){
                        $scope.tip = 0;//有值页面显示
                        $scope.content_upload = 1;//加载按钮显示
                    }
                    $scope.parsefloat = function(index){
                        index++;
                        if(index==$scope.Majorinfog.length){
                            return parseInt(index/5)==index/5?true:false;
                        }else{
                            return false;
                        }


                    };
                    $rootScope.all_page = $scope.page.page_total;//总页数
                    $rootScope.this_page = $scope.page.page_current;//当前页
                }
            }
        });

        //检测页面top
        $scope.upload = function(){//点击加载更多
            $rootScope.this_page++;
            $http({//请求公开课-列表接口
                url: app._baseUrl + 'Qy/PublicCurr/index',
                method: 'POST',
                data:{
                    page_no:$rootScope.this_page
                },
                headers: {'Content-Type': 'application/x-www-form-urlencoded'}
            }).success(function(res){
                $scope.Majorinfog =$scope.Majorinfog.concat( res.data);
                if($rootScope.this_page==$rootScope.all_page){
                    $scope.content_upload = 0;//加载按钮隐藏
                }
            })
        };
        //给进入直播一个点击事件
        $scope.enter_into = function(url,is_Privilege,public_id){
            if(is_Privilege==1){//当有权限查看时
                $http({//请求公开课-经验值
                    url: app._baseUrl + 'Qy/PublicCurr/UserIntegral',
                    method: 'POST',
                    data:{
                        public_id:public_id
                    },
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                });
                window.open(url);
            }else{//没有权限查看
                $scope.limits();
            }
        }
        //给查看录播一个点击事件
        $scope.recorded = function(id,is_Privilege,aliyun_video_id){
            if(is_Privilege==1){
                // var url = $state.href('app.periods',{public_id :id,aliyun_video_id:aliyun_video_id});
                // window.open(url,'_blank');
                var url = $state.href('app.compaliVideo',{public_id :id,aliyun_video_id:aliyun_video_id});
                window.open(url,'_blank');
            }else{
                $scope.limits();
            }

        }
        //提示没有权限
        $scope.limits = function(){
            $scope.sec = 5;
            var interval = setInterval(function() {//设置定时器
                if($scope.sec > 0) {
                    $scope.sec--;
                    $scope.tipShow = true;//提示显示
                    $('.black_patch').fadeIn(600);
                } else {
                    clearInterval(interval);
                    $scope.tipShow = true;
                    $('.black_patch').fadeOut(600);
                }
                $scope.$digest();//脏数据检验
            }, 500)
        };
        //下载资料
        $scope.download_video = function(file_url){
            window.location.href = encodeURI(file_url);
        }
    })
});